package com.tz.zczc.web.controller.impl;

import com.tz.zczc.core.service.KeywordsService;
import com.tz.zczc.domain.model.common.Response;
import com.tz.zczc.domain.model.entity.Keywords;
import com.tz.zczc.web.controller.KeywordsController;
import io.swagger.annotations.ApiParam;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author:Mark
 * @Description:
 * @Date: Created on 16:58 2018-12-5
 * @Modify by:
 */

@RestController
public class KeywordsControllerImpl implements KeywordsController {

  @Autowired
  private KeywordsService keywordsService;

  @Override
  public Response addRecords(HttpServletRequest request, HttpServletResponse response,
     @ApiParam(required = true,name = "keywords",value = "搜索的内容") @RequestParam(required = true,value = "keywords") String keywords) {
    Keywords keywords1=new Keywords();
    keywords1.setKeyWord(keywords);
    System.out.println("传入的关键词诶"+keywords);
    Boolean flag = keywordsService.addRecordSelective(keywords1);
    return Response.suc(flag);
  }

  @Override
  public Response delRecordsByIds(HttpServletRequest request, HttpServletResponse response,
     @ApiParam(value = "要删除的id值") @NotEmpty(message = "传入的id不能为空")  @RequestBody List<String> ids) {
    Boolean flag = keywordsService.logicDeleteById(ids);
    return Response.suc(flag);
  }

  @Override
  public Response getRecordsByPage(HttpServletRequest request, HttpServletResponse response,
      @ApiParam(required = false,name="pageSize",value = "页大小")
      @RequestParam(required = false ,defaultValue ="20",value = "pageSize")
      @Min(value = 1, message = "页大小不能小于1") Integer pageSize,
      @ApiParam(required = false,name = "pageNum",value = "页码")
      @RequestParam(required = false,value = "pageNum",defaultValue = "1")
      @Min(value = 1, message = "页码不能小于1") Integer pageNum) {
    return Response.suc(keywordsService.selectKeywordsByPages(pageSize,pageNum));
  }

  @Override
  public Response updateRecordsSelective(HttpServletRequest request, HttpServletResponse response,
      @ApiParam(required = true,name = "keywords",value = "要修改的对象") @RequestBody Keywords keywords) {
    System.out.println("修改的地下"+keywords);
    return Response.suc(keywordsService.updateByid(keywords));
  }
}
